# import sys
#
# sys.path.append('.')
# sys.path.append('..')
# sys.path.append('...')

from datetime import datetime
from . import admin
from . import views
from flask import render_template, redirect, request, url_for, flash, make_response
from src.app import uploadfiles
from .forms import *
from ..models import *
from ..commAPI import apiObj, hostObj
from src.app import db
from src.app import elineStat
import json
from sqlalchemy.orm import aliased
from ..DB_API import cDBtoDo
import os


# 上传文件
@admin.route('/upload', methods=['POST', 'GET'])
def upload_file():
    form = cFormFileUp()
    if form.validate_on_submit():
        filename = uploadfiles.save(form.photo.data, 'root/tmp/upload')
        file_url = uploadfiles.url(filename)
        print("---------------", filename, file_url)
    else:
        file_url = None
    return render_template('admin/upload.html', form=form, file_url=file_url)


@admin.route('/index')
def adminIndex():
    searchform = cFormAdminSearch()
    return render_template('admin/index.html', form=searchform)


@admin.route('/syscheck')
def syscheck():
    searchform = cFormAdminSearch()
    return render_template('admin/syscheck.html', form=searchform)


@admin.route('/school')
def schoollist():
    searchform = cFormAdminSearch()
    dbObj = cDBtoDo()

    schlist = dbObj.getSchool()

    return render_template('admin/school.html', formseach=searchform, data=schlist)


@admin.route('/schooladd', methods=['GET', 'POST'])
def schoolAdd():
    searchform = cFormAdminSearch()
    mainform = cFormSchoolAdd()
    if mainform.validate_on_submit():

        schoolname = mainform.schoolname.data
        id = str(apiObj.createGUID(schoolname))

        schooladdr = mainform.schooladdr.data
        schoolphone = mainform.schoolpohne.data
        schoolfox = mainform.schoolfox.data
        homepage = mainform.homepage.data
        logodir = 'root/tmp/upload/logo'
        print('mainform.logo.data=', mainform.logo.data)
        # logopath = apiObj.savefile(source=mainform.logo.data, filedir=logodir, filename=id+'_logo')
        # logo_url = uploadfiles.url(logopath)
        logopath = uploadfiles.save(mainform.logo.data, logodir)
        logo_url = uploadfiles.url(logopath)
        print('logpath=', logopath)
        print('logo_url=', logo_url)
        #################################3
        disc = mainform.disc.data
        print('disc=', disc)
        discdir = 'root/tmp/upload/disc'
        path = apiObj.savefile(source=disc, filedir=discdir, filename=id + '_disc')
        disc_url = uploadfiles.url(path)
        print('disc_url=', disc_url)

        #####################################

        schoolItem = tSchool(id=id,
                             name=schoolname,
                             addr=schooladdr,
                             phone=schoolphone,
                             fox=schoolfox,
                             homepage=homepage,
                             logo='',
                             disc=disc_url)
        # db.session.add(schoolItem)
        # db.session.commit()
        return redirect(url_for('admin.schoollist'))
    else:
        file_url = None
    return render_template('admin/add/school.html', formseach=searchform, formmain=mainform)


import random


def gen_rnd_filename():
    filename_prefix = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
    return '%s%s' % (filename_prefix, str(random.randrange(1000, 10000)))


@admin.route('/ckupload/', methods=['POST'])
def addschooldisc():
    callback = request.args.get("CKEditorFuncNum")
    if request.method == 'POST' and 'upload' in request.files:
        fileobj = request.files['upload']
        fname, fext = os.path.splitext(fileobj.filename)
        rnd_name = '%s%s' % ('aaa', fext)
        filepath = os.path.join('~/tmp/', 'upload', rnd_name)
        # 检查路径是否存在，不存在则创建
        dirname = os.path.dirname(filepath)
        if not os.path.exists(dirname):
            try:
                os.makedirs(dirname)
            except:
                error = 'ERROR_CREATE_DIR'
        elif not os.access(dirname, os.W_OK):
            error = 'ERROR_DIR_NOT_WRITEABLE'
        if not error:
            fileobj.save(filepath)
            url = url_for('static', filename='%s/%s' % ('upload', rnd_name))
        else:
            error = 'post error'
        res = """

        <script type="text/javascript">
         window.parent.CKEDITOR.tools.callFunction(%s, '%s', '%s');
        </script>

        """ % (callback, url, error)

        (callback, url, error)
        response = make_response(res)
        response.headers["Content-Type"] = "text/html"
        return response

@admin.route('/collegelist')
def collegelist():
    searchform = cFormAdminSearch()
    item = list()
    dbObj = cDBtoDo()
    enablelist = dbObj.getCollege(elineStat.enable)
    disablelist = dbObj.getCollege(elineStat.disable)

    return render_template('admin/college.html', formseach=searchform, enabledata=enablelist, disabledata=disablelist)


@admin.route('/collegeAdd', methods=['POST', 'GET'])
def collegeAdd():
    searchform = cFormAdminSearch()
    mainform = cFormCollegeAdd()

    if mainform.validate_on_submit():
        collegename = mainform.name.data
        createtime = datetime.now()
        schoolid = mainform.schooleid.data

        item = tCollege(id=str(apiObj.createGUID(collegename)), name=collegename, createtime=createtime,
                        shoolId=schoolid)
        db.session.add(item)
        db.session.commit()
        return redirect(url_for('admin.collegelist'))

    return render_template('admin/add/college.html', formseach=searchform, formmain=mainform)


@admin.route('/majorlist')
def majorlist():
    searchform = cFormAdminSearch()
    dbObj = cDBtoDo()
    enablelist = dbObj.getMajor(enable=elineStat.enable)
    disablelist = dbObj.getMajor(enable=elineStat.disable)

    return render_template('admin/major.html', formseach=searchform, enabledata=enablelist, disabledata=disablelist)


@admin.route('/majorAdd', methods=['POST', 'GET'])
def majorAdd():
    searchform = cFormAdminSearch()
    mainform = cFormMajorAdd()
    if mainform.validate_on_submit():
        majorname = mainform.name.data
        createtime = datetime.now()
        collegeid = mainform.collegeid.data

        item = tMajor(id=str(apiObj.createGUID(majorname)), name=majorname, createtime=createtime,
                      collegeid=collegeid)
        db.session.add(item)
        db.session.commit()
        return redirect(url_for('admin.majorlist'))

    return render_template('admin/add/major.html', formseach=searchform, formmain=mainform)


@admin.route('/clazzlist')
def clazzlist():
    searchform = cFormAdminSearch()
    dbObj = cDBtoDo()
    enablelist = dbObj.getClazz(enable=elineStat.enable)
    disablelist = dbObj.getClazz(enable=elineStat.enable)

    return render_template('admin/clazz.html', formseach=searchform, enabledata=enablelist, disabledata=disablelist)


@admin.route('/clazzAdd', methods=['POST', 'GET'])
def clazzAdd():
    searchform = cFormAdminSearch()
    mainform = cFormClazzAdd()
    if mainform.validate_on_submit():
        majorname = mainform.name.data
        createtime = datetime.now()
        majorid = mainform.major.data

        item = tClazz(id=str(apiObj.createGUID(majorname)), name=majorname, createtime=createtime,
                      majorid=majorid)
        db.session.add(item)
        db.session.commit()
        return redirect(url_for('admin.clazzlist'))
    return render_template('admin/add/clazz.html', formseach=searchform, formmain=mainform)


@admin.route('/pathlist')
def pathlist():
    searchform = cFormAdminSearch()
    dbObj = cDBtoDo()
    itemenable = dbObj.getPath(enable=elineStat.enable)
    itemex = dbObj.getPath(enable=elineStat.examine)
    itemdisable = dbObj.getPath(enable=elineStat.disable)
    return render_template('admin/path.html', formseach=searchform, enabledata=itemenable, examdata=itemex,
                           disabledata=itemdisable)


@admin.route('/pathadd', methods=['GET', 'POST'])
def pathAdd():
    searchform = cFormAdminSearch()
    mainform = cFormPathAdd()

    if mainform.validate_on_submit():
        pathname = mainform.name.data
        createtime = datetime.now()
        modiftime = createtime

        item = tPath(id=str(apiObj.createGUID(pathname)), name=pathname, createtime=createtime,
                     modiftime=modiftime)
        db.session.add(item)
        db.session.commit()
        return redirect(url_for('admin.pathlist'))
    return render_template('admin/add/path.html', formseach=searchform, formmain=mainform)


@admin.route('/pathsteplist')
def pathsteplist():
    searchform = cFormAdminSearch()
    dbObj = cDBtoDo()
    itemEnable = dbObj.getPathStep(enable=elineStat.enable)
    itemExam = dbObj.getPathStep(enable=elineStat.examine)
    itemDisable = dbObj.getPathStep(enable=elineStat.disable)
    itemRefuce = dbObj.getPathStep(enable=elineStat.refuce)

    return render_template('admin/pathstep.html', formseach=searchform, enabledata=itemEnable, examdata=itemExam,
                           disabledata=itemDisable, refucedata=itemRefuce)


@admin.route('/pathstepadd', methods=['GET', 'POST'])
def pathstepAdd():
    searchform = cFormAdminSearch()
    mainform = cFormPathStepAdd()

    if mainform.validate_on_submit():
        stepname = mainform.name.data
        createtime = datetime.now()
        pathid = mainform.pathname.data
        level = mainform.level.data

        item = tPathStep(id=str(apiObj.createGUID(stepname)), name=stepname, createtime=createtime,
                         pathid=pathid, level=int(level))
        db.session.add(item)
        db.session.commit()
        return redirect(url_for('admin.pathsteplist'))
    return render_template('admin/add/pathstep.html', formseach=searchform, formmain=mainform)


@admin.route('/courselist')
def courselist():
    searchform = cFormAdminSearch()
    dbObj = cDBtoDo()
    itemEnable = dbObj.getCourse(enable=elineStat.enable)
    itemExam = dbObj.getCourse(enable=elineStat.examine)
    itemDisable = dbObj.getCourse(enable=elineStat.disable)
    itemRefuce = dbObj.getCourse(enable=elineStat.refuce)

    return render_template('admin/course.html', formseach=searchform, enabledata=itemEnable, examdata=itemExam,
                           disabledata=itemDisable, refucedata=itemRefuce)


@admin.route('/courseadd', methods=['POST', 'GET'])
def courseAdd():
    searchform = cFormAdminSearch()
    mainform = cFormCourseAdd()

    if mainform.validate_on_submit():
        name = mainform.name.data
        createtime = datetime.now()
        disc = mainform.disc.data

        item = tCourse(id=str(apiObj.createGUID(name)), name=name, createtime=createtime,
                       disc=disc)
        db.session.add(item)
        db.session.commit()
        return redirect(url_for('admin.courselist'))
    return render_template('admin/add/course.html', formseach=searchform, formmain=mainform)



@admin.route('/rolelist')
def rolelist():
    searchform = cFormAdminSearch()
    dbObj = cDBtoDo()
    itemenable = dbObj.getRole(enable=elineStat.enable)
    itemex = dbObj.getRole(enable=elineStat.examine)
    itemdisable = dbObj.getRole(enable=elineStat.disable)
    itemrefuce = dbObj.getRole(enable=elineStat.refuce)

    return render_template('admin/role.html', formseach=searchform, enabledata=itemenable, examdata=itemex,
                           disabledata=itemdisable, refucedata=itemrefuce)

@admin.route('/roleadd',methods=['POST','GET'])
def roleAdd():
    searchform = cFormAdminSearch()
    mainform = cFormRoleAdd()

    if mainform.validate_on_submit():
        name = mainform.name.data
        createtime = datetime.now()

        item = tRole(id=str(apiObj.createGUID(name)), name=name, createtime=createtime)
        db.session.add(item)
        db.session.commit()
        return redirect(url_for('admin.rolelist'))
    return render_template('admin/add/role.html', formseach=searchform, formmain=mainform)

@admin.route('/alluserlist')
def alluserlist():
    searchform = cFormAdminSearch()
    dbObj = cDBtoDo()
    itemenable = dbObj.getAllUser(enable=elineStat.enable)
    itemexam = dbObj.getAllUser(enable=elineStat.examine)
    itemdisable = dbObj.getAllUser(enable=elineStat.disable)
    itemrefuce = dbObj.getAllUser(enable=elineStat.refuce)

    return render_template('admin/alluser.html', formseach=searchform, enabledata=itemenable, examdata=itemexam,
                           disabledata=itemdisable, refucedata=itemrefuce)


@admin.route('/alluseradd',methods=['POST','GET'])
def alluserAdd():
    searchform = cFormAdminSearch()
    mainform = cFormUserAdd()

    if mainform.validate_on_submit():
        name = mainform.name.data
        createtime = datetime.now()
        rolename = mainform.rolename.data

        item = tAllUser(id=str(apiObj.createGUID(name)), name=name, createtime=createtime,
                        roleid=rolename)
        db.session.add(item)
        db.session.commit()
        return redirect(url_for('admin.alluserlist'))
    return render_template('admin/add/alluser.html', formseach=searchform, formmain=mainform)


@admin.route('/playerlist/<matchid>', methods=['POST', 'GET'])
def playerlist(matchid):
    searchform = cFormAdminSearch()
    dbObj = cDBtoDo()
    enableitem = dbObj.getPlayer(matchid, elineStat.enable)
    examitem = dbObj.getPlayer(matchid, elineStat.examine)
    disableitem = dbObj.getPlayer(matchid, elineStat.disable)
    refuceitem = dbObj.getPlayer(matchid, elineStat.refuce)
    return render_template('admin/player.html', formseach=searchform, enabledate=enableitem, examdata=examitem,
                           disabledata=disableitem, refucedata=refuceitem)


@admin.route('/judgerlist/<matchid>', methods=['POST', 'GET'])
def judgerlist(matchid):
    searchform = cFormAdminSearch()
    dbObj = cDBtoDo()
    itemenable = dbObj.getJudger(matchid, elineStat.enable)
    itemexam = dbObj.getJudger(matchid, elineStat.examine)
    itemdisable = dbObj.getJudger(matchid, elineStat.disable)
    itemrefuce = dbObj.getJudger(matchid, elineStat.refuce)

    return render_template('admin/judger.html', formseach=searchform, enabledata=itemenable, examdata=itemexam,
                           disabledata=itemdisable, refucedata=itemrefuce)

@admin.route('/judgeradd',methods=['POST','GET'])
def judgerAdd():
    searchform = cFormAdminSearch()
    mainform = cFormJugerAdd()

    if mainform.validate_on_submit():
        userid = mainform.userid.data
        matchid = mainform.matchid.data
        createtime = datetime.now()
        rolename = mainform.rolename.data

        item = tJudger(id=str(apiObj.createGUID(userid)), userid=userid, matchid=matchid, createtime=createtime)
        db.session.add(item)
        db.session.commit()
        return redirect(url_for('admin.judgerlist'))
    return render_template('admin/add/judger.html', formseach=searchform, formmain=mainform)


@admin.route('/matchlist')
def matchlist():
    searchform = cFormAdminSearch()
    dbObj = cDBtoDo()
    enableitem = dbObj.getMatch(enable=elineStat.enable)
    examitem = dbObj.getMatch(enable=elineStat.examine)
    disableitem = dbObj.getMatch(enable=elineStat.disable)
    refuceitem = dbObj.getMatch(enable=elineStat.refuce)

    return render_template('admin/match.html', formseach=searchform, enabledata=enableitem, examdata=examitem,
                           disabledata=disableitem, refucedata=refuceitem)


@admin.route('/matchadd')
def matchAdd():
    searchform = cFormAdminSearch()
    maininfo = cFormMatchAdd()
    if maininfo.validate_on_submit():
        id = maininfo.id.data
        name = maininfo.name.data
        db.session.commit()
        return redirect(url_for('admin.matchlist'))
    return render_template('admin/add/match.html', formseach=searchform, formmain=maininfo)




@admin.route('/modeltypelist')
def modeltypelist():
    searchform = cFormAdminSearch()
    dbObj = cDBtoDo()
    itemenable = dbObj.getModelType(enable=elineStat.enable)
    itemex = dbObj.getModelType(enable=elineStat.examine)
    itemdisable = dbObj.getModelType(enable=elineStat.disable)
    itemrefuce = dbObj.getModelType(enable=elineStat.refuce)

    return render_template('admin/modeltype.html', formseach=searchform, enabledata=itemenable,
                           examdata=itemex, disabledata=itemdisable, refucedata=itemrefuce)


@admin.route('/modeltypeAdd', methods=['POST', 'GET'])
def modeltypeAdd():
    searchform = cFormAdminSearch()
    mainform = cFormModelTypeAdd()

    if mainform.validate_on_submit():
        name = mainform.name.data
        createtime = datetime.now()

        item = tModelType(id=str(apiObj.createGUID(name)), name=name, createtime=createtime)
        db.session.add(item)
        db.session.commit()
        return redirect(url_for('admin.modeltypelist'))
    return render_template('admin/add/modeltype.html', formseach=searchform, formmain=mainform)

@admin.route('/modellist',methods=['POST','GET'])
def modellist():
    searchForm = cFormAdminSearch()
    dbObj = cDBtoDo()
    itemEnables = dbObj.getCaptionModel(elineStat.enable)
    itemExs = dbObj.getCaptionModel(elineStat.examine)
    itemDisables = dbObj.getCaptionModel(elineStat.disable)
    itemRefuces = dbObj.getCaptionModel(elineStat.refuce)

    headform = cFormShowListHead()

    return render_template('admin/model.html', formseach=searchForm, dataEnable=itemEnables, dataEx=itemExs,
                           dataUnable=itemDisables, dataRefuce=itemRefuces,headform=headform)

@admin.route('/modelAdd',methods=['POST','GET'])
def modelAdd():
    searchform = cFormAdminSearch()
    mainform = cFormModelAdd()

    if request.method == 'POST':
        name = mainform.name.data
        createtime = datetime.now()
        modeftime = datetime.now()
        disc = mainform.disc.data
        modeltype = mainform.type.data
        modelfile = mainform.modelfile.data

        item = tCaptionmodel(id=str(apiObj.createGUID(name)), name=name, disc=disc, modeltype=modeltype,
                             modelfile=modelfile, createtime=createtime, modeftime=modeftime)
        db.session.add(item)
        db.session.commit()
        return redirect(url_for('admin.modellist'))
    return render_template('admin/add/model.html', formseach=searchform, formmain=mainform)


@admin.route('/modelAcc/<reqid>')
def modelDoEnableOne(reqid):
    searchForm = cFormAdminSearch()
    print(reqid)
    modelSimple = tCaptionmodel.query.filter_by(id=str(reqid)).first()
    print(str(modelSimple))
    if modelSimple is not None:
        modelSimple.flag = elineStat.enable
        db.session.add(modelSimple)
        db.session.commit()

    dbObj = cDBtoDo()
    itemEnables = dbObj.getCaptionModel(elineStat.enable)
    itemExs = dbObj.getCaptionModel(elineStat.examine)
    itemDisables = dbObj.getCaptionModel(elineStat.disable)
    itemRefuces = dbObj.getCaptionModel(elineStat.refuce)

    headform = cFormShowListHead()

    return render_template('admin/model.html', formseach=searchForm, dataEnable=itemEnables, dataEx=itemExs,
                           dataUnable=itemDisables, dataRefuce=itemRefuces, headform=headform)

@admin.route('/coursestatisticslist')
def coursestatisticslist():
    searchform = cFormAdminSearch()
    return render_template('admin/coursestatistics.html', formseach=searchform)


@admin.route('/matchstatisticslist')
def matchstatisticslist():
    searchform = cFormAdminSearch()

    itemenable = list()
    itemex = list()
    itemdisable = list()

    userlist = db.session.query(tMatch.id, tMatch.name, tMatch.createteacherid, tMatch.modelsid,
                                tMatch.createtime, tMatch.startime, tMatch.endtime, tMatch.studcount,
                                tMatch.judgescount, tMatch.flag)
    for x in userlist:
        if x is not None:
            if x.flag == elineStat.enable:
                qdata = dict()
                qdata['id'] = x[0]
                qdata['name'] = x[1]
                qdata['createteacherid'] = x[2]
                qdata['modelsid'] = x[3]
                qdata['createtime'] = str(x[4])
                qdata['startime'] = str(x[5])
                qdata['endtime'] = str(x[6])
                qdata['studcount'] = x[7]
                qdata['judgescount'] = x[8]
                qdata['flag'] = x[9]
                itemenable.append(qdata)
            elif x.flag == elineStat.examine:
                qdata = dict()
                qdata['id'] = x[0]
                qdata['name'] = x[1]
                qdata['createteacherid'] = x[2]
                qdata['modelsid'] = x[3]
                qdata['createtime'] = str(x[4])
                qdata['startime'] = str(x[5])
                qdata['endtime'] = str(x[6])
                qdata['studcount'] = x[7]
                qdata['judgescount'] = x[8]
                qdata['flag'] = x[9]
                itemex.append(qdata)
            else:
                qdata = dict()
                qdata['id'] = x[0]
                qdata['name'] = x[1]
                qdata['createteacherid'] = x[2]
                qdata['modelsid'] = x[3]
                qdata['createtime'] = str(x[4])
                qdata['startime'] = str(x[5])
                qdata['endtime'] = str(x[6])
                qdata['studcount'] = x[7]
                qdata['judgescount'] = x[8]
                qdata['flag'] = x[9]
                itemdisable.append(qdata)
    dataEnable = json.dumps(itemenable)
    dataEx = json.dumps(itemex)
    dataUnable = json.dumps(itemdisable)

    return render_template('admin/matchstatistics.html', formseach=searchform, dataEnable=dataEnable, dataEx=dataEx,
                           dataUnable=dataUnable)


@admin.route('/captionAdd',methods=['POST','GET'])
def chapterAdd():
    searchform = cFormAdminSearch()
    maininfo = cFormCaptionAdd()
    if maininfo.validate_on_submit():
        id = maininfo.chptionid.data
        name = maininfo.chptionname.data

        createtime = datetime.now()
        modeftime = datetime.now()

        disc = maininfo.disc.data
        model = maininfo.chptionModel.data
        type = maininfo.chptiontype.data
        level = maininfo.chptionIndex.data

        item = tCaption(id=id, name=name, createtime=createtime, disc=disc, modeftime=modeftime, modelname=model,
                        level=level, type=type)
        db.session.add(item)
        db.session.commit()
        return redirect(url_for('admin.captionlist'))
    return render_template('admin/add/caption.html', formseach=searchform, formmain=maininfo)

@admin.route('/captionlist',methods=['POST','GET'])
def  captionlist():
    searchform = cFormAdminSearch()
    dbObj = cDBtoDo()
    itemenable = dbObj.getChapter(enable=elineStat.enable)
    itemexam = dbObj.getChapter(enable=elineStat.examine)
    itemdisable = dbObj.getChapter(enable=elineStat.disable)
    itemrefuce = dbObj.getChapter(enable=elineStat.refuce)

    return render_template('admin/caption.html', formseach=searchform, enabledata=itemenable, examdata=itemexam,
                           disabledata=itemdisable, refucedata=itemrefuce)

@admin.route('/playeradd')
def playerAdd():
    searchform = cFormAdminSearch()
    maininfo = cFormPlayerAdd()
    if maininfo.validate_on_submit():
        id=maininfo.id.data
        name=maininfo.name.data
        db.session.commit()
        return redirect(url_for('admin.playerlist'))
    return render_template('admin/add/player.html', formseach=searchform, formmain=maininfo)

#学习章节日志
@admin.route('/studlog')
def studlog():
    searchform = cFormAdminSearch()

    itemenable = list()
    itemex = list()
    itemdisable = list()

    stdid = aliased(tAllUser.id, name='stdid')
    stdname = aliased(tAllUser.name, name='stdname')
    teachid = aliased(tAllUser.id, name='teachid')
    teachname = aliased(tAllUser.name, name='teachname')

    loglist = db.session.query(tCourselog.id, stdid, stdname, teachid, teachname,
                               tCourselog.startime, tCourselog.endtime, tCourselog.captionmodeid, tCaptionmodel.name,
                               tCourselog.copyeid, tCourselog.flag).filter(
        stdid == tAllUser.id and teachid == tAllUser.id
        and tCourselog.captionmodeid == tCaptionmodel.id)

    for x in loglist:
        if x is not None:
            if x.flag == elineStat.enable:
                qdata = dict()
                qdata['id'] = x[0]
                qdata['stdid'] = x[1]
                qdata['stdname'] = x[2]
                qdata['teachid'] = x[3]
                qdata['teachname'] = x[4]
                qdata['startime'] = str(x[5])
                qdata['endtime'] = str(x[6])
                qdata['modelid'] = x[7]
                qdata['modelname'] = x[8]
                qdata['copyid'] = x[9]
                qdata['flag'] = x[10]
                itemenable.append(qdata)
            elif x.flag == elineStat.examine:
                qdata = dict()
                qdata['id'] = x[0]
                qdata['stdid'] = x[1]
                qdata['stdname'] = x[2]
                qdata['teachid'] = x[3]
                qdata['teachname'] = x[4]
                qdata['startime'] = str(x[5])
                qdata['endtime'] = str(x[6])
                qdata['modelid'] = x[7]
                qdata['modelname'] = x[8]
                qdata['copyid'] = x[9]
                qdata['flag'] = x[10]
                itemex.append(qdata)
            else:
                qdata = dict()
                qdata['id'] = x[0]
                qdata['stdid'] = x[1]
                qdata['stdname'] = x[2]
                qdata['teachid'] = x[3]
                qdata['teachname'] = x[4]
                qdata['startime'] = str(x[5])
                qdata['endtime'] = str(x[6])
                qdata['modelid'] = x[7]
                qdata['modelname'] = x[8]
                qdata['copyid'] = x[9]
                qdata['flag'] = x[10]
                itemdisable.append(qdata)

    dataEnable = json.dumps(itemenable)
    dataEx = json.dumps(itemex)
    dataUnable = json.dumps(itemdisable)
    return render_template('admin/stdlog.html', formseach=searchform, dataEnable=dataEnable, dataEx=dataEx,
                           dataUnable=dataUnable)

#比赛日志
@admin.route('/matchlog')
def matchlog():
    pass
#联系日志
@admin.route('/Practice')
def practicelog():
    pass